package com.wobangkj.common.api.crud;

import com.wobangkj.common.model.crud.Dynamic;
import com.wobangkj.common.service.DynamicService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.sql.Timestamp;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Slf4j
@RestController
@RequestMapping("/dynamic")
public class DynamicController {
    @Autowired
    private DynamicService dynamicService;

    @PostMapping(value = "/create")
    public Object create(@RequestBody Dynamic data) {
        // 创建时间
        data.setCreatetime(Timestamp.valueOf(LocalDateTime.now()));
        return dynamicService.create(data);
    }

    @PutMapping(value = "/update")
    public Object update(@RequestBody Dynamic dynamic) {

        return dynamicService.update(dynamic);
    }

    @DeleteMapping(value = "/delete/{id}")
    public Object delete(@PathVariable(value = "id") Long id) {
        return dynamicService.delete(id);
    }

    @GetMapping("/id")
    public Object id(Long id) {

        return dynamicService.id(id);
    }


    @GetMapping("/search")
    public Object search(@RequestParam(required = false) Map<String, Object> params, Dynamic dynamic) {
        return dynamicService.search(params, dynamic);
    }

    @GetMapping("/list")
    public List<Map> list(){
        return dynamicService.list();
    }

    @GetMapping("/idlist")
    public List<Map> idlist(long id){
        return dynamicService.idlist(id);
    }

    @GetMapping("/getListByName")
    public List<Map> getListByName(String name){
        return dynamicService.getListByName(name);
    }

    @GetMapping("/getListByTag")
    public List<Map> getListByTag(@RequestParam("circle_name")String circle_name,@RequestParam("dynamic_company_tag")String dynamic_company_tag,@RequestParam("dynamic_major_tag")String dynamic_major_tag,@RequestParam("dynamic_job_tag")String dynamic_job_tag,@RequestParam("dynamic_other_tag")String dynamic_other_tag){
        return dynamicService.getListByTag(circle_name,dynamic_company_tag, dynamic_major_tag, dynamic_job_tag, dynamic_other_tag);
    }

    @GetMapping("/getListByTagNoCircle")
    public List<Map> getListByTagNoCircle(@RequestParam("dynamic_company_tag")String dynamic_company_tag,@RequestParam("dynamic_major_tag")String dynamic_major_tag,@RequestParam("dynamic_job_tag")String dynamic_job_tag,@RequestParam("dynamic_other_tag")String dynamic_other_tag){
        return dynamicService.getListByTagNoCircle(dynamic_company_tag, dynamic_major_tag, dynamic_job_tag, dynamic_other_tag);
    }

    @PostMapping(value = "/updateForward")
    public Object updateDynamicForward(Long id) {
        return dynamicService.updateDynamicForward(id);
    }
}
